-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: v8.1 refactoring tools batch 2 #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Five features based on Cursor agent feedback from live refactoring trial: 1. Function-level complexity in auditRisk — wire tree-sitter complexity analyzer into audit, returning per-function cyclomatic+cognitive scores sorted by complexity (top 10 per file). Falls back to heuristic. 2. Graceful degradation messaging — new DegradationWarning type with capability percentages and fix commands. Wired into explore, understand, prepareChange, auditRisk, and findDeadCode MCP handlers. 3. Test gap analysis — new testgap package + analyzeTestGaps MCP tool. Cross-references complexity analysis with SCIP references or heuristic name matching to identify untested functions, sorted by risk. 4. Richer prepareChange for rename/extract — RenameDetail (call sites, type refs, imports with context snippets) and ExtractDetail (boundary analysis) added as parallel goroutines in PrepareChange. 5. Unified planRefactor compound tool — aggregates prepareChange + auditRisk + analyzeTestGaps in parallel, generates ordered refactoring steps by change type (rename/extract/delete/modify). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Four new features extending the refactoring toolset: 1. Dependency cycle detection (findCycles) - Tarjan's SCC algorithm to detect circular dependencies at module/directory/file granularity, with break-cost analysis suggesting which edge to remove. 2. Move/relocate change type - adds "move" to prepareChange and planRefactor, scanning for affected imports (SCIP-precise or heuristic fallback) and target path conflicts. 3. Extract variable flow analysis - tree-sitter-based parameter/return detection for extract refactorings, with CGO/non-CGO build tags for graceful degradation. 4. Suggested refactoring detection (suggestRefactorings) - proactive detection combining complexity, coupling, dead code, and audit analyzers in parallel to surface prioritized opportunities. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🟡 Change Impact Analysis
Blast Radius: 0 modules, 1 files, 247 unique callers 📝 Changed Symbols (678)
🎯 Affected Downstream (20)
Recommendations
Generated by CKB |
🔐 Security Audit Results
📦 Dependency VulnerabilitiesFound 7 vulnerability(ies) across 2 scanner(s) DetailsTrivy (4 findings)
OSV-Scanner (3 findings)
📜 License IssuesFound 144 non-permissive license(s) Details
Generated by CKB Security Audit | View Details | Security Tab |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #128 +/- ##
=========================================
+ Coverage 44.9% 45.5% +0.5%
=========================================
Files 350 365 +15
Lines 60028 61829 +1801
=========================================
+ Hits 27004 28165 +1161
- Misses 31188 31761 +573
- Partials 1836 1903 +67
Flags with carried forward coverage won't be shown. Click here to find out more. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
CKB Analysis
Risk factors: Large PR with 37 files • High churn: 5871 lines changed • Touches 13 hotspot(s)
🎯 Change Impact Analysis · 🟡 MEDIUM · 678 changed → 20 affected
Symbols changed in this PR:
Downstream symbols affected:
Recommendations:
💣 Blast radius · 0 symbols · 10 tests · 0 consumersTests that may break:
🔥 Hotspots · 13 volatile files
📦 Modules · 2 at risk
📊 Complexity · 9 violations
💡 Quick wins · 10 suggestions
📚 Stale docs · 143 broken references
Generated by CKB · Run details |
- cycles/detector_test.go: Tarjan SCC algorithm, break cost, severity - query/cycles_test.go: graph extraction, cycle summary - query/prepare_move_test.go: target conflicts, heuristic import scanning - query/prepare_extract_test.go: signature generation, language inference - suggest/analyzer_test.go: severity helpers, dedup, file listing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add CHANGELOG entries for cycle detection, move/relocate, extract flow analysis, and suggested refactoring detection. Add 23 MCP integration tests for all batch 2 features. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Cover the previously untested extract/analyzer.go with CGO-tagged tests: - Full Analyze() pipeline for Go, JavaScript, and Python source - classifyVariables() logic: parameter/return/local classification, modified tracking, empty input, unused-in-region exclusion - AST walking: findContainingFunction, collectDeclarations, collectReferences, keyword filtering - Helper functions: isKeyword, langToExtension, node type helpers Documents known limitation: Go assignment_statement wraps LHS in expression_list, so `x = expr` doesn't trigger isModified detection. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- extract/analyzer.go: return parse error instead of nil (nilerr), remove unused strings import and lines variable - suggest/analyzer.go: propagate filepath.Walk errors instead of swallowing them (nilerr) - prepare_move_test.go: use context.TODO() instead of nil context (staticcheck SA1012) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The extract flow analyzer always operated on the entire file because startLine/endLine were never passed from MCP through to the analyzer. This made parameter/return detection useless since all variables are both defined and used within the same (whole-file) range. Adds startLine/endLine to prepareChange MCP tool definition, parses them in the handler, and threads them through PrepareChangeOptions and PlanRefactorOptions to getPrepareExtractDetail. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Adds 4 new refactoring analysis features to CKB v8.1, building on the batch 1 foundation (
feature/v8.1-refactoring-tools):findCycles): Tarjan's SCC algorithm detects circular dependencies at module/directory/file granularity, with break-cost analysis suggesting which edge to removemovetoprepareChangeandplanRefactorwith import scanning (SCIP-precise or heuristic fallback) and target conflict detectionsuggestRefactorings): Proactive detection combining complexity, coupling, dead code, and audit analyzers in parallel to surface prioritized opportunitiesIncludes batch 1 changes (not yet merged to develop).
24 files changed (16 new, 8 modified), +3,115 lines, 51 new tests
New files
cycles/detector.go,query/cycles.go,mcp/tool_impls_cycles.goquery/prepare_move.goextract/types.go,extract/analyzer.go,extract/stub.gosuggest/types.go,suggest/analyzer.go,query/suggest.go,mcp/tool_impls_suggest.gocycles/detector_test.go,query/cycles_test.go,query/prepare_move_test.go,query/prepare_extract_test.go,suggest/analyzer_test.goModified files
mcp/presets.go,mcp/presets_test.go,mcp/token_budget_test.go,mcp/tool_impls_compound.go,mcp/tools.go,query/compound.go,query/compound_refactor.go,query/prepare_extract.goTest plan
go build ./cmd/ckbpassesgo test ./internal/...— full suite passes (57 packages)gofmt -lclean on all new/modified filesfindCycleswithgranularity=directoryreturns cycle data or empty resultprepareChangewithchangeType: "move"returns MoveDetailprepareChangewithchangeType: "extract"returns populated Parameters/Returns (CGO)suggestRefactoringswith a target scope returns prioritized suggestions🤖 Generated with Claude Code